<template>
	<view class="page bargain">
		<view class="bargain-list">
			<view class="bg-color-white border-radius10 padding16 margin22" v-for="(item,index) in list" :key="item.id">
				<my-bargain-item :item="item"></my-bargain-item>
			</view>
		</view>
		<view style="margin-bottom:30upx">
		  <banner-ad></banner-ad>
		</view>
		<!-- <uni-load-more :status="status" :contentText="contentText" v-if="total" @tap="loadList"></uni-load-more> -->
		<view class="list-no-data" v-if="!list || list.length==0">
			<image src="../../../static/images/ui_meiyoujiangping.png" mode="widthFix" />
			<text @tap="toDraw">暂无抽奖，立即去参与~</text>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	import myBargainItem from '@/components/home/my-bargain-item/index.vue'
	let gData = {};
	let _self;
	export default {
		components: {
			uniLoadMore,
			myBargainItem
		},
		data() {
			return {
				list: [],
				total: 0,
				status: "more",
				contentText: {
					contentdown: "点击加载",
					contentrefresh: "正在加载...",
					contentnomore: ""
				}
			}
		},
		onLoad(options) {
			_self = this;
		},
		onShow(){
			this.initList()
		},
		onUnload() {
			gData = {}; /*因为全局变量会保存，再次打开该页面时会造成一些数据错误 */
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.initList();
			uni.stopPullDownRefresh()
		},
		// 上拉加载
		onReachBottom() {
			// this.loadList();
		},
		methods: {
			// 初始化列表
			initList() {
				gData.page = 0;
				this.list = [];
				this.status = "more";
				this.loadList();
			},
			// 加载列表
			async loadList() {
				// if (this.status == "more") {
				// 	const page = gData.page + 1;
				// 	this.status = "loading";
				// 	const pageSize = 10;
				// 	// uni.showNavigationBarLoading();
				// 	try {
						let data = await this.$api.bargain.getMyBargainList({
							// page: page, // 页数
							// rows: pageSize //
						});
						console.log(data)
						this.list=data
						
					// 	const addList = data.list || [];
					// 	addList.map((item) => {
					// 		if (item.lotteryTime) {
					// 			const arr = this.$util.formatTimestamp(item.lotteryTime)
					// 			item.lotteryTime = arr[1] + '月' + arr[2] + '日 ' + arr[3] + ':' + arr[4];
					// 		}
					// 	})
					// 	this.list = this.list.concat(addList)
					// 	gData.page = page;
					// 	this.total = data.total;
					// 	const noMore = (page * pageSize) >= data.total;
					// 	this.status = noMore ? "noMore" : "more";
					// 	// uni.hideNavigationBarLoading()
					// } catch (e) {
					// 	this.status = "more";
					// 	console.log('request fail', e);
					// }
				// };
			},
			toDrawDetails(id){
				uni.navigateTo({
					url:'/pages/draw/details/details?prizeId='+id
				})
			},
			toDraw(){
				uni.switchTab({
					url:'/pages/tabBar/draw/index'
				})
			},
			// ---------------------------------------
			// 保存二维码
			setFormId(e) {
				// _self.$api.setFormId(e);
			},
		},
	}
</script>

<style lang="scss" scoped>
	.bargain {
		background-color: #581ae1;
	}
	
	.list-no-data{
		image{
			display: block;
			width: 260rpx;
			margin: 160rpx auto 60rpx;
		}
		text{
			display: block;
			width: 100%;
			color: white;
			text-align: center;
			font-size: 28rpx;
			opacity: 0.8;
		}
	}
</style>
